﻿using UnityEngine;

/// <summary>
/// 站立
/// </summary>
public class FSMStateStand : FSMStateBase
{
    protected override string getName => "stand";

    private float speed => UnitDefine.BASE_SPEED * fsm.entity.attribute.speed;

    protected override void OnExecute()
    {
        var axis = fsm.parameters.GetParam<float>("horizontalAxis");
        LookAt(axis);
        Move(axis);
    }

    private void LookAt(float axis)
    {
        if (axis != 0)
            fsm.entity.animator.direction = new Vector3(axis, 1, 1);
    }

    private void Move(float axis)
    {
        var easingAxis = Mathf.MoveTowards(fsm.entity.physics.velocity.x / speed, axis, Time.deltaTime / UnitDefine.BASE_ACCE_TIME);
        fsm.entity.physics.velocity = new Vector2(easingAxis * speed, fsm.entity.physics.velocity.y);
    }
}
